package SEG_ApplicationLayer;

import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import CommonApplicationLayer.*;
import SEG_BusinessLayer.SEG_AccesoBL;
import SEG_EntityLayer.SEG_AccesoEL;
import SEG_EntityLayer.SEG_MenuEL;
import SEG_EntityLayer.SEG_OpcionEL;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;

public class FrmSEG_MaestroEmpresa extends JInternalFrame 
{
    //--------------------------------------------------------------------------
    // <editor-fold defaultstate="collapsed" desc="Variables">
    
        private byte sysEmpresa;
        private short sysUsuario;
        private String sysLogin;
    
    // </editor-fold>

    //--------------------------------------------------------------------------
    // <editor-fold defaultstate="collapsed" desc="Seguridad">
        
        private void ObtenerDatosSesion()
        {
            sysEmpresa = InfoComun.getInstancia().getIdEmpresa();
            sysUsuario = InfoComun.getInstancia().getIdUsuario();
            sysLogin = InfoComun.getInstancia().getLogin();
        }
        
    // </editor-fold>

    //--------------------------------------------------------------------------
    // <editor-fold defaultstate="collapsed" desc="Apariencia">
    
    // </editor-fold>

    //--------------------------------------------------------------------------
    // <editor-fold defaultstate="collapsed" desc="ControlEventos">
        public FrmSEG_MaestroEmpresa() 
        {
            initComponents();
            ObtenerDatosSesion();
        }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        btnCancelar = new boton.FButton();
        btnCancelar1 = new boton.FButton();
        btnCancelar2 = new boton.FButton();
        btnCancelar3 = new boton.FButton();
        btnCancelar4 = new boton.FButton();
        btnCancelar5 = new boton.FButton();
        fDockingTab1 = new pageTab.FDockingTab();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        fTable1 = new table.FTable();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setMinimumSize(new java.awt.Dimension(410, 316));
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(239, 246, 253));

        jLabel1.setFont(new java.awt.Font("Lucida Fax", 1, 10)); // NOI18N
        jLabel1.setText("Empresas");

        jLabel2.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        jLabel2.setText("Razón Social:");

        jTextField1.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        jLabel3.setText("RUC:");

        jTextField2.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/door_in.png"))); // NOI18N
        btnCancelar.setText("Salir");
        btnCancelar.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        btnCancelar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCancelar.setMargin(new java.awt.Insets(2, 4, 2, 4));
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnCancelar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/page_excel.png"))); // NOI18N
        btnCancelar1.setText("Exportar");
        btnCancelar1.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        btnCancelar1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelar1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCancelar1.setMargin(new java.awt.Insets(2, 4, 2, 4));
        btnCancelar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar1ActionPerformed(evt);
            }
        });

        btnCancelar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/page_white_edit.png"))); // NOI18N
        btnCancelar2.setText("Editar");
        btnCancelar2.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        btnCancelar2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelar2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCancelar2.setMargin(new java.awt.Insets(2, 4, 2, 4));
        btnCancelar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar2ActionPerformed(evt);
            }
        });

        btnCancelar3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/delete.png"))); // NOI18N
        btnCancelar3.setText("Eliminar");
        btnCancelar3.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        btnCancelar3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelar3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCancelar3.setMargin(new java.awt.Insets(2, 4, 2, 4));
        btnCancelar3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar3ActionPerformed(evt);
            }
        });

        btnCancelar4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/disk.png"))); // NOI18N
        btnCancelar4.setText("Guardar");
        btnCancelar4.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        btnCancelar4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelar4.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCancelar4.setMargin(new java.awt.Insets(2, 4, 2, 4));
        btnCancelar4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar4ActionPerformed(evt);
            }
        });

        btnCancelar5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/page_white_add.png"))); // NOI18N
        btnCancelar5.setText("Nuevo");
        btnCancelar5.setFont(new java.awt.Font("Lucida Fax", 0, 10)); // NOI18N
        btnCancelar5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelar5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCancelar5.setMargin(new java.awt.Insets(2, 4, 2, 4));
        btnCancelar5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar5ActionPerformed(evt);
            }
        });

        fTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        fTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        fTable1.setAutoscrolls(false);
        fTable1.setHeaderHeight(20);
        jScrollPane2.setViewportView(fTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                .addContainerGap())
        );

        fDockingTab1.addTab("Lista de Empresas", jPanel1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel1))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(90, 90, 90)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(fDockingTab1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(0, 86, Short.MAX_VALUE)
                                .addComponent(btnCancelar5, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelar2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelar4, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelar3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(fDockingTab1, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar3, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar5, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jScrollPane1.setViewportView(jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnCancelar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar1ActionPerformed
        FixedColumnTable fct = new FixedColumnTable(2, jScrollPane2);
    }//GEN-LAST:event_btnCancelar1ActionPerformed

    private void btnCancelar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelar2ActionPerformed

    private void btnCancelar3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar3ActionPerformed
        FixedColumnTable fct = new FixedColumnTable(1, jScrollPane2);
    }//GEN-LAST:event_btnCancelar3ActionPerformed

    private void btnCancelar4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelar4ActionPerformed

    private void btnCancelar5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar5ActionPerformed
            try {
                List<SEG_AccesoEL> lista = SEG_AccesoBL.getInstancia().ObtenerAccesoUsuario((byte)1, (byte)1, (short)1);
                Set<SEG_MenuEL> menu = new TreeSet<SEG_MenuEL>(new Comparator(){
                    @Override
                    public int compare(Object o1, Object o2) {  
                        SEG_MenuEL e1 = (SEG_MenuEL) o1;  
                        SEG_MenuEL e2 = (SEG_MenuEL) o2;  
                        int codigo1 = e1.getOrden();  
                        int codigo2 = e2.getOrden();  
  
                        if (codigo1 > codigo2) {  
                            return 1;  
                        } else if (codigo1 < codigo2) {  
                            return -1;  
                        } else {  
                            return 0;  
                        } 
                    }  
                });
                
                for (SEG_AccesoEL acceso : lista)
                {
                    menu.add(acceso.getOpcion().getMenu());
                }
                for (SEG_MenuEL m : menu)
                {
                    JOptionPane.showMessageDialog(this, m.getNombre(), SMSComun.smsEmpresa, JOptionPane.ERROR_MESSAGE);
                }
            } catch (Exception ex) {
                Logger.getLogger(FrmSEG_MaestroEmpresa.class.getName()).log(Level.SEVERE, null, ex);
            }
    }//GEN-LAST:event_btnCancelar5ActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        
    }//GEN-LAST:event_formInternalFrameOpened

    // </editor-fold>

    //--------------------------------------------------------------------------
    // <editor-fold defaultstate="collapsed" desc="Funcionalidad">
    
    // </editor-fold>
    
    //--------------------------------------------------------------------------
    // <editor-fold defaultstate="collapsed" desc="AccesoDatos">
    
    // </editor-fold>
    
    //--------------------------------------------------------------------------
    // <editor-fold defaultstate="collapsed" desc="Validacion">
    
    // </editor-fold>

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private boton.FButton btnCancelar;
    private boton.FButton btnCancelar1;
    private boton.FButton btnCancelar2;
    private boton.FButton btnCancelar3;
    private boton.FButton btnCancelar4;
    private boton.FButton btnCancelar5;
    private pageTab.FDockingTab fDockingTab1;
    private table.FTable fTable1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables

}
